package com.joysuch.wwyt.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.joysuch.wwyt.api.entity.ApiAlarmSubscribe;
import com.joysuch.wwyt.api.mapper.ApiAlarmSubscribeMapper;
import com.joysuch.wwyt.api.service.ApiAlarmSubscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zqw
 * @since 2022-06-07
 */
@Service
public class ApiAlarmSubscribeServiceImpl extends ServiceImpl<ApiAlarmSubscribeMapper, ApiAlarmSubscribe> implements ApiAlarmSubscribeService {

    @Autowired
    private ApiAlarmSubscribeMapper apiAlarmSubscribeMapper;

    @Override
    public List<ApiAlarmSubscribe> findUnsubscribedDatas() {
        return apiAlarmSubscribeMapper.findUnsubscribedDatas();
    }

    @Override
    public ApiAlarmSubscribe findByAlarmTypeAndUrl(String alarmType, String url, String orgCode, Long tenentId) {
        return apiAlarmSubscribeMapper.findByAlarmTypeAndUrl(alarmType, url, orgCode, tenentId);
    }

    @Override
    public void updateStatus(String orgCode, Long tenentId) {
        apiAlarmSubscribeMapper.update(new ApiAlarmSubscribe(), new UpdateWrapper<ApiAlarmSubscribe>()
                .set("status", 0)
                .set("org_code", orgCode)
                .set("tenent_id", tenentId)
                .eq("org_code", orgCode)
                .eq("tenent_id", tenentId)
                .eq("status", 1));
    }
}
